home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import symjava.sql.SQLException;
-
- abstract class BinaryField extends Field {
- byte[] _binData;
-
- void read(DataInputStream is) throws SQLException, IOException, ErrorException {
- super.read(is);
- this._binData = new byte[0];
- }
-
- void write(DataOutputStream os) throws IOException {
- super.write(os);
- }
-
- public String getString() throws SQLException {
- return ((Field)this).isNull() ? null : new String(this._binData, 0, 0, this._binData.length);
- }
-
- public byte[] getBytes() throws SQLException {
- return ((Field)this).isNull() ? new byte[0] : this._binData;
- }
-
- public InputStream getAsciiStream() throws SQLException {
- return new BinaryInputStream(this._binData);
- }
-
- public InputStream getUnicodeStream() throws SQLException {
- return new BinaryInputStream(this._binData);
- }
-
- public InputStream getBinaryStream() throws SQLException {
- return new BinaryInputStream(this._binData);
- }
-
- public void setString(String x) throws SQLException {
- this._binData = new byte[x.length()];
- x.getBytes(0, x.length() - 1, this._binData, 0);
- super._null = false;
- }
-
- public void setBytes(byte[] x) throws SQLException {
- this._binData = x;
- super._null = false;
- }
-
- public void setStream(InputStream x, int length) throws SQLException {
- if (length >= 0 && length <= 255) {
- byte[] b = new byte[length];
-
- try {
- x.read(b, 0, length);
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
-
- this._binData = b;
- super._null = false;
- } else {
- throw new SQLException("Stream length out of range.");
- }
- }
-
- public void setAsciiStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
-
- public void setUnicodeStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
-
- public void setBinaryStream(InputStream x, int length) throws SQLException {
- this.setStream(x, length);
- }
- }
-